package com.wh.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wh.order.pojo.OrderReviewer;
import com.wh.order.service.IOrderReviewerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wh.order.mapper.OrderReviewerMapper;
import com.wh.order.dto.OrderReviewerDto;

import java.util.Arrays;
import java.util.List;

/**
 * 业务实现类：
 */
@Service
public class OrderReviewerServiceImpl implements IOrderReviewerService {

    @Autowired
    private OrderReviewerMapper orderReviewerMapper;

    @Override
    public void add(OrderReviewer orderReviewer){
        orderReviewerMapper.insert(orderReviewer);
    }

    @Override
    public void deleteById(Long id){
        orderReviewerMapper.deleteById(id);
    }

    @Transactional
    @Override
    public void patchDel(List<Long> ids){
        orderReviewerMapper.deleteBatchIds(ids);
    }

    @Override
    public void updateById(OrderReviewer orderReviewer){
        orderReviewerMapper.updateById(orderReviewer);
    }

    @Override
    public OrderReviewer findOne(Long id){
        return orderReviewerMapper.selectById(id);
    }

    @Override
    public List<OrderReviewer>findAll(){
        return orderReviewerMapper.selectList(null);
    }

    @Override
    public IPage<OrderReviewer>findByPage(OrderReviewerDto orderReviewerDto){
        //1.创建查询条件
        QueryWrapper<OrderReviewer> qw = new QueryWrapper<>();
        //qw.like("xxx",orderReviewerDto.getXxx());
        //qw.or();
        //qw.like("xxx",orderReviewerDto.getXxx());
        //2.组件分页数据
        IPage<OrderReviewer> page = new Page<>(orderReviewerDto.getCurrentPage(), orderReviewerDto.getPageSize());
        page.setRecords(orderReviewerMapper.findByPage(page,qw));
        page.setTotal(orderReviewerMapper.selectCount(qw));
        //3.返回
        return page;
    }

    @Override
    public OrderReviewer findone(String orderSn) {
        QueryWrapper<OrderReviewer> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("order_sn",orderSn);
       return orderReviewerMapper.selectOne(objectQueryWrapper);

    }
}
